package com.zshan.clinic.cms.controller.config;


import com.zshan.clinic.admin.entity.vo.MedicalFieldSupportTreeVo;
import com.zshan.clinic.admin.service.config.MedicalFieldService;
import com.zshan.clinic.cms.common.core.controller.BaseController;
import com.zshan.clinic.cms.common.core.domain.AjaxResult;
import com.zshan.clinic.cms.common.core.domain.entity.SysUser;
import com.zshan.clinic.common.util.page.PageInfo;
import com.zshan.clinic.database.model.MedicalField;
import com.zshan.clinic.database.model.MedicalFieldSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 诊所信息
 */
@RestController
@RequestMapping("/config/medicalField/")
public class MedicalFieldController extends BaseController {


    @Autowired
    private MedicalFieldService medicalFieldService;


    /**
     * 查询病历字段列表
     * @param fieldName 病历字段名
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getMedicalFieldListByCondition")
    public AjaxResult getMedicalFieldListByCondition(@RequestParam(name = "fieldName", required = false) String fieldName,
                                                     @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        PageInfo<MedicalField> pageInfo = medicalFieldService.getMedicalFieldListByCondition(fieldName, pageNo, pageSize);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 添加病历字段
     * @param medicalField
     * @return
     */
    @PostMapping("/addMedicalField")
    public AjaxResult addMedicalField(@RequestBody MedicalField medicalField) {
        SysUser sysUser = getUser();
        medicalField.setCreateUserId(sysUser.getUserId());
        medicalField.setCreateBy(sysUser.getUserName());
        medicalFieldService.addMedicalField(medicalField);
        return AjaxResult.success();
    }

    /**
     * 修改病历字段
     * @param medicalField
     * @return
     */
    @PostMapping("/updateMedicalField")
    public AjaxResult updateMedicalField(@RequestBody MedicalField medicalField) {
        SysUser sysUser = getUser();
        medicalField.setUpdateUserId(sysUser.getUserId());
        medicalField.setUpdateBy(sysUser.getUserName());
        medicalFieldService.updateMedicalField(medicalField);
        return AjaxResult.success();
    }

    /**
     * 删除病历字段
     * @param medicalField
     * @return
     */
    @PostMapping("/deleteMedicalField")
    public AjaxResult deleteMedicalField(@RequestBody MedicalField medicalField) {
        SysUser sysUser = getUser();
        medicalField.setUpdateUserId(sysUser.getUserId());
        medicalField.setUpdateBy(sysUser.getUserName());
        medicalFieldService.deleteMedicalField(medicalField);
        return AjaxResult.success();
    }

    /**
     * 查询病历字段支持树
     * @param fieldId 病历字段ID
     * @return
     */
    @GetMapping("/getFieldSupportTree")
    public AjaxResult getFieldSupportTree(@RequestParam(name = "fieldId", required = false) Long fieldId) {
        List<MedicalFieldSupportTreeVo> supportTreeList = medicalFieldService.getFieldSupportTree(fieldId);
        return AjaxResult.success(supportTreeList);
    }

    /**
     * 添加病历字段支持
     * @param medicalFieldSupport
     * @return
     */
    @PostMapping("/addFieldSupport")
    public AjaxResult addFieldSupport(@RequestBody MedicalFieldSupport medicalFieldSupport) {
        SysUser sysUser = getUser();
        medicalFieldSupport.setCreateUserId(sysUser.getUserId());
        medicalFieldSupport.setCreateBy(sysUser.getUserName());
        medicalFieldService.addFieldSupport(medicalFieldSupport);
        return AjaxResult.success();
    }

    /**
     * 修改病历字段支持
     * @param medicalFieldSupport
     * @return
     */
    @PostMapping("/updateFieldSupport")
    public AjaxResult updateFieldSupport(@RequestBody MedicalFieldSupport medicalFieldSupport) {
        SysUser sysUser = getUser();
        medicalFieldSupport.setUpdateUserId(sysUser.getUserId());
        medicalFieldSupport.setUpdateBy(sysUser.getUserName());
        medicalFieldService.updateFieldSupport(medicalFieldSupport);
        return AjaxResult.success();
    }

    /**
     * 删除病历字段支持
     * @param medicalFieldSupport
     * @return
     */
    @PostMapping("/deleteFieldSupport")
    public AjaxResult deleteFieldSupport(@RequestBody MedicalFieldSupport medicalFieldSupport) {
        SysUser sysUser = getUser();
        medicalFieldSupport.setUpdateUserId(sysUser.getUserId());
        medicalFieldSupport.setUpdateBy(sysUser.getUserName());
        medicalFieldService.deleteFieldSupport(medicalFieldSupport);
        return AjaxResult.success();
    }

}
